package flc.ast.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.ToastUtils;

import flc.ast.BaseAc;
import flc.ast.R;
import flc.ast.databinding.ActivityWifiSecurityBinding;

public class WifiSecurityActivity extends BaseAc<ActivityWifiSecurityBinding> {


    @Override
    protected int onCreate() {
        return R.layout.activity_wifi_security;
    }

    @Override
    protected void initView() {
        mDataBinding.ivWifiSecurityBack.setOnClickListener(v -> onBackPressed());

        mDataBinding.tvRetest.setOnClickListener(this);
    }

    @Override
    protected void onClickCallback(View v) {
        switch (v.getId()){
            case R.id.tvRetest://重新检测
                if (NetworkUtils.isWifiConnected()) {
                    getData();
                } else {
                    ToastUtils.showShort(getString(R.string.not_connect_wifi));
                }
                break;
        }
    }

    @Override
    protected void initData() {
        if (NetworkUtils.isWifiConnected()) {
            mDataBinding.tvWifiName.setText(getString(R.string.current_network_text) + NetworkUtils.getSSID());
            getData();
        } else {
            mDataBinding.tvWifiName.setText(getString(R.string.no_connect));
            mDataBinding.llInfo.setVisibility(View.GONE);
        }
    }

    private void getData(){
        showDialog(getString(R.string.loading));
        mDataBinding.llInfo.setVisibility(View.GONE);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                dismissDialog();
                mDataBinding.llInfo.setVisibility(View.VISIBLE);
            }
        },1000);
    }

}